package com.ds.lens.data.service.dao;

import com.ds.lens.data.service.dao.entity.LensMonitor;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface LensMonitorSnapshotDao {

    String COLUMNS = "id, name, integration_id, detection_method, application_id, state, mute, mute_start_time, " +
            "mute_end_time, is_delete, run_status, tags, version, creator, created_time, mender, modified_time, version_time ";

    @Select({"select ",
            COLUMNS,
            "from lens_monitor_snapshot where id = #{id} and version = #{version} "
    })
    @Results(id = "lensMonitor", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "integration_id", property = "integrationId", jdbcType = JdbcType.BIGINT),
            @Result(column = "detection_method", property = "detectionMethod", jdbcType = JdbcType.TINYINT),
            @Result(column = "application_id", property = "applicationId", jdbcType = JdbcType.BIGINT),
            @Result(column = "state", property = "state", jdbcType = JdbcType.SMALLINT),
            @Result(column = "mute", property = "mute", jdbcType = JdbcType.BIT),
            @Result(column = "mute_start_time", property = "muteStartTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "mute_end_time", property = "muteEndTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "is_delete", property = "isDelete", jdbcType = JdbcType.BIT),
            @Result(column = "run_status", property = "runStatus", jdbcType = JdbcType.TINYINT),
            @Result(column = "tags", property = "tags", jdbcType = JdbcType.VARCHAR),
            @Result(column = "version", property = "version", jdbcType = JdbcType.INTEGER),
            @Result(column = "creator", property = "creator", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "mender", property = "mender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "modified_time", property = "modifiedTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "version_time", property = "versionTime", jdbcType = JdbcType.TIMESTAMP)
    })
    LensMonitor selectSnapshoot(@Param("id") Long id, @Param("version") Integer version);


    @Insert({"insert into lens_monitor_snapshot",
            " (select ",
            COLUMNS,
            " from lens_monitor where id = #{id})"
    })
    int insert(Long id);

}
